//
//  ReleaseResultsView.m
//  yunyan
//
//  Created by haichuang on 2018/4/3.
//  Copyright © 2018年 haichuang. All rights reserved.
//

#import "ReleaseResultsView.h"

@implementation ReleaseResultsView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-(void)initResultsViewWithClear:(BOOL)isClear{
    _isClear = isClear;
    [self initResultsView];
    
}
-(void)initResultsView{
      WeakSelf;
     self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
    
    if (_isClear) {
        UIImageView * image = [[UIImageView alloc] init];
        [self addSubview:image];
        [image mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo (weakSelf.mas_left).offset(70.f);
            make.right.equalTo (weakSelf.mas_right).offset(-70.f);
            make.centerY.equalTo (weakSelf.mas_centerY).offset (-60.0f);
            make.height.equalTo (image.mas_width).multipliedBy (0.55);
           
        }];
        image.image = [UIImage imageNamed:@"system-setup_clean_meg"];
        
    }else{
        
       
        UIView * resultView = [[UIView alloc] init];
        [self addSubview:resultView];
        [resultView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo (weakSelf.mas_left).offset (28.0f);
            make.right.equalTo (weakSelf.mas_right).offset (-28.0f);
            make.centerY.equalTo (weakSelf.mas_centerY).offset (-60.0f);
            make.height.equalTo (@(160.f));
        }];
        resultView.backgroundColor = [UIColor whiteColor];
        resultView.layer.masksToBounds = YES;
        resultView.layer.cornerRadius = 5;
        
        //关闭按钮
        UIButton * closeBtn = [[UIButton alloc] init];
        [resultView addSubview:closeBtn];
        [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.right.equalTo (resultView);
            make.height.width.equalTo (@(30.0f));
        }];
        [closeBtn setImage:[UIImage imageNamed:@"release_close_default"] forState:UIControlStateNormal];
        [closeBtn addTarget:self action:@selector(closeBtnClicked) forControlEvents:UIControlEventTouchUpInside];
        
        //发布label
        UILabel * topLabel = [[UILabel alloc] init];
        [resultView addSubview:topLabel];
        [topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(resultView.mas_centerX);
            make.top.equalTo (closeBtn.mas_bottom).offset (20.0f);
        }];
        topLabel.text = @"发布成功";
        topLabel.textColor = RGBA(255, 197, 60, 1);
        topLabel.font = [UIFont systemFontOfSize:18.0f ];
        
        self. buttomLabel = [[UILabel alloc]init];
        [resultView addSubview:self.buttomLabel];
        [self.buttomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(resultView.mas_left).offset (20.f);
            make.right.equalTo (resultView.mas_right).offset (-20.f);
            make.top.equalTo (topLabel.mas_bottom).offset (14.0f);
            
        }];
        self.buttomLabel.numberOfLines = 0;
        self.buttomLabel.textAlignment = NSTextAlignmentCenter;
        NSString * str = @"你可以到个人中心我的随手拍查看";
        
        
        NSDictionary *AttributeDict = [NSDictionary dictionaryWithObjectsAndKeys:
                                       [UIFont systemFontOfSize:15.0f],NSFontAttributeName,
                                       RGBA(153, 153, 153, 1),NSForegroundColorAttributeName,nil];
        NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:str attributes:AttributeDict];
        NSRange littleTextHourRange = [str rangeOfString:@"个人中心"];
        
        [AttributedStr addAttribute:NSForegroundColorAttributeName
         
                              value:RGBA(81, 158, 238, 1 )
         
                              range:littleTextHourRange];
        
        self.buttomLabel.attributedText = AttributedStr;
        
        [self.buttomLabel tapAction:^{
            
             [[NSNotificationCenter  defaultCenter] postNotificationName:@"goToCent" object:@"goToCent"];
        }];
        
    }
  
 
}

-(void)closeBtnClicked{
    [self removeFromSuperview];
    
     [[NSNotificationCenter  defaultCenter] postNotificationName:@"NotgoToCent" object:@"NotgoToCent"];
}

-(void)goToCenter:(UIButton *)btn{
    
    
   
    
    
}


@end
